package com.sky.com.sky.web.app;

import com.sky.dto.SetmealDTO;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    SetmealService setmealService;

    /**
     * 查询分类下的套餐列表
     * @param categoryId
     * @return
     * **/
    @GetMapping("/list")
    @Cacheable(value = "setmealCache",key = "'setmeal_'+#categoryId")
    public Result list(@RequestParam Long categoryId){
        //封装查询条件
        SetmealDTO setmealDTO = SetmealDTO.builder()
                .categoryId(categoryId)
                .status(1)
                .build();
        //调用service查询
        List<Setmeal> list = setmealService.paramList(setmealDTO);
        //返回结果
        return Result.success(list);

    }

}
